Structuring functional programs by using monads
نویسنده
چکیده
The notion of monads originates from the category theory. It became popular in the programming languages community after Moggi proposed a way to use monads to structure denotational semantics. Wadler and others showed how this can be eeectively used as a methodology for building interpreters. Monads are capable of capturing individual language features in a modular way. This paper evaluates two modular approaches for building monadic interpreters -Steele's pseudomonads and Liang, Hudak & Jones's monad transformers. We also consider the the problem of feature interaction in the monad transformers setting. 1 Monads: Introduction and Motivation Is there a practical use for category theory? Certainly the programming language theory is a good example. Many categorical concepts led to important discoveries about programming languages and vice-versa, many ideas from the category theory were motivated by the programming languages research. Monads probably t in both groups. Category theorists invented monads in the 1960's to express certain properties of universal algebra. Two decades later people started studying programming language aspects of monads. Among the biggest contributors to this promising idea were Eu-genio Moggi 6] and Philip Wadler 7]. The original idea was to use monads for presenting the deno-tational semantics of complex languages. Monads seemed to be able to capture a variety of commonly found language properties. At the same time they can be used as a clean and extensible technique for implementing these features in interpreters. The key feature is that monads provide us with a convenient notion of a computation. Using this, we can enrich our computational model by distinguishing between the values and the computations. For example, two programs (computations) that calculate the same answer, but generate diierent screen outputs should certainly be considered diierent. This is hard to achieve in a setting where computations are viewed statically, as pure functions. Using monads, we can precisely specify the desired level of distinction between computations. This balances the tradeoo between impure and pure functional languages from the language im-plementor's point of view. On one hand, pure languages, such as Haskell, beneet from the power of equational reasonong. On the other hand, many desired features seemed to be very hard to implement without using impure constructs, such as arrays, references and certainly I/O. Monads provided solutions that combined the best of both approaches. We should note that monads are not special programming language constructs-they are simply an example of a good data abstraction. …
منابع مشابه
Combining Monads
Monads provide a way of structuring functional programs. Most real applications require a combination of primitive monads. Here we describe how some monads may be combined with others to yield a combined monad.
متن کاملMonads and Effects
A tension in language design has been between simple semantics on the one hand, and rich possibilities for side-effects, exception handling and so on on the other. The introduction of monads has made a large step towards reconciling these alternatives. First proposed by Moggi as a way of structuring semantic descriptions, they were adopted by Wadler to structure Haskell programs. Monads have be...
متن کاملExtensions: A Technique for Structuring Functional-Logic Programs
Monads are a technique widely used in functional programming languages to address many different problems. This paper presents extensions, a functional-logic programming technique that constitutes an alternative to monads in several situations. Extensions permit the definition of easily reusable functions in the same way as monads, but are based on simpler concepts taken from logic programming,...
متن کاملDomain Separation by Construction
Language-based approaches to security typically use static type systems to control information flow, relying on type inference to distinguish secure programs from insecure ones. This paper advocates a novel approach to language-based security: by structuring software with monads (a form of abstract data type for effects), we are able to maintain separation of effects by construction. The thesis...
متن کامل. Monads and More
From their semantic origins to their use in structuring effectful computations, monads are now also used as a programming pattern to structure code in a number of important scenarios, including functional reactivity, information flow tracking and probabilistic computation. However, whilst these examples are inspired by monads they are not strictly speaking monadic but rather something more gene...
متن کاملPromotional Transformation on Monadic Programs
Monads, proposed by Moggi [16] of their use in structuring denotational descriptions and then popularized by Wadler[21], are becoming an increasingly important tool for structural functional programming[8, 10, 11]. The reason is that monads provide a uniform framework for describing a wide range of programming language features including, for example, state, I/O, continuations, exceptions, pars...
متن کامل